package controlador;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.List;

import dao.RemitoTransporteDAO;
import dominio.RemitoTransporte;
import dto.RemitoTransporteTO;
import remoto.IGestionRemitosTransporte;

public class GestionRemitosTransporte extends UnicastRemoteObject implements IGestionRemitosTransporte, Serializable {
	private static final long serialVersionUID = 1L;

	public GestionRemitosTransporte() throws RemoteException {
		super();
	}

	@Override
	public int guardarRemitoTransporte(RemitoTransporteTO remitoTransporte) throws RemoteException {
		return RemitoTransporteDAO.getInstance().guardarRemitoTransporte(RemitoTransporte.fromDTO(remitoTransporte));
	}

	@Override
	public RemitoTransporteTO buscarRemitoTransporte(int id) throws RemoteException {
		RemitoTransporte rt = RemitoTransporteDAO.getInstance().buscarRemitoTransporte(id);
		if (rt != null)
			return rt.getDTO();
		return null;
	}

	@Override
	public List<RemitoTransporteTO> listarRemitosPendientes() {
		List<RemitoTransporteTO> lista = new ArrayList<RemitoTransporteTO>();
		List<RemitoTransporte> remitos = RemitoTransporteDAO.getInstance().listarRemitosPendientes();
		for (RemitoTransporte r : remitos)
			lista.add(r.getDTO());
		return lista;
	}
}